Use for, split(), and if to create a Statement that will print out words that start with 's':
In [1]:
st = 'Print only the words that start with s in this sentence'
In [7]:
#Code here
print st.split()
for word in st.split():
if word[0] == 's':
print word
In [11]:
[word for word in st.split() if word[0] == 's']
Out[11]:
Use range() to print all the even numbers from 0 to 10.
In [13]:
#Code Here
[number for number in xrange(0,11) if number %2 ==0 ]
Use List comprehension to create a list of all numbers between 1 and 50 that are divisible by 3.
In [15]:
#Code in this cell
[num for num in xrange(1,51) if num % 3 ==0]
Out[15]:
Go through the string below and if the length of a word is even print "even!"
In [6]:
st = 'Print every word in this sentence that has an even number of letters'
In [17]:
#Code in this cell
for word in st.split():
if len(word) % 2 == 0:
print word
Write a program that prints the integers from 1 to 100. But for multiples of three print "Fizz" instead of the number, and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".
In [20]:
#Code in this cell
for num in xrange(1,101):
if num % 3 == 0 and num % 5 == 0:
print num, 'FizzBuzz'
elif num % 5 == 0:
print num, 'Buzz'
elif num % 3 ==0:
print num, 'Fizz'
Use List Comprehension to create a list of the first letters of every word in the string below:
In [21]:
st = 'Create a list of the first letters of every word in this string'
In [24]:
#Code in this cell
[word[0] for word in st.split()]
Out[24]:
In [1]:
l = [2,3,4,74,4,4]
In [ ]:
l.ap